/*
 * Copyright 2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mx.ymate.security.impl;

import com.mx.ymate.security.ISecurity;
import com.mx.ymate.security.ISecurityConfig;
import com.mx.ymate.security.handler.ILoginHandler;
import com.mx.ymate.security.handler.IUserHandler;
import net.ymate.platform.core.module.IModuleConfigurer;
import net.ymate.platform.core.module.impl.DefaultModuleConfigurable;

/**
 * DefaultSaTokenConfig generated By ModuleMojo on 2022/07/03 12:39
 *
 * @author YMP (https://www.ymate.net/)
 */
public final class DefaultSecurityConfigurable extends DefaultModuleConfigurable {

    public static Builder builder() {
        return new Builder();
    }

    private DefaultSecurityConfigurable() {
        super(ISecurity.MODULE_NAME);
    }

    public static final class Builder {

        private final DefaultSecurityConfigurable configurable = new DefaultSecurityConfigurable();

        private Builder() {
        }

        public Builder enabled(boolean enabled) {
            configurable.addConfig(ISecurityConfig.ENABLED, String.valueOf(enabled));
            return this;
        }

        public Builder client(String client) {
            configurable.addConfig(ISecurityConfig.CLIENT, client);
            return this;
        }

        public Builder loginHandlerClass(ILoginHandler loginHandlerClass) {
            configurable.addConfig(ISecurityConfig.LOGIN_HANDLER_CLASS, loginHandlerClass.getClass().getName());
            return this;
        }

        public Builder userHandlerClass(IUserHandler userHandlerClass) {
            configurable.addConfig(ISecurityConfig.USER_HANDLER_CLASS, userHandlerClass.getClass().getName());
            return this;
        }

        public Builder errorCount(int errorCount) {
            configurable.addConfig(ISecurityConfig.ERROR_COUNT, String.valueOf(errorCount));
            return this;
        }

        public Builder openLog(boolean openLog) {
            configurable.addConfig(ISecurityConfig.OPEN_LOG, String.valueOf(openLog));
            return this;
        }

        public Builder excludePathPatterns(String excludePathPatterns) {
            configurable.addConfig(ISecurityConfig.EXCLUDE_PATH_PATTERNS, excludePathPatterns);
            return this;
        }

        public IModuleConfigurer build() {
            return configurable.toModuleConfigurer();
        }
    }
}